<?php
/**
 * 广告挂件
 * 模板调用方法 {:R('advert/index', array($id), 'Widget')}
 */
namespace Common\Widget;
use Think\Controller;
class FlinkWidget extends Controller  {

    public function index($id) {
        $id = intval($id);
        $list = array();
        foreach( D('flink')->where(array('status'=>1))->order('ordid asc')->select() as $val){
            if($val['name'] && $val['content'] && $val['img']){
                $list['top'][] = $val;
            }else if( !empty($val['img'])){
                $list['img'][] = $val;
            }else if($val['name']){
                $list['text'][] = $val;
            }
        }
        $this->assign('list',$list);
        $this->display(dirname(__FILE__).'/Flink/index.html');
    }

    private function _get_html($ad, $board_info) {
        $html = $ad['content'];
        $size_html = '';
        $board_info['width'] && $size_html .= 'width="'.$board_info['width'].'"';
        $board_info['height'] && $size_html .= ' height="'.$board_info['height'].'"';

        $go_url = empty($ad['url']) || $ad['url'] == 'http://' ? 'javascript:void(0);' : U(CONTROLLER_NAME.'/go',array('id'=>$ad['id']));

        switch ($ad['type']) {
            case 'image':
                $html  = '<a title="'.$ad['name'].'" href="'.$go_url.'" target="_blank">';
                $html .= '<img alt="'.$ad['name'].'" src="'.get_img($ad['content']).'" '.$size_html.'>';
                $html .= '</a>';
                break;
            case 'flash':
                $html  = '<a title="'.$ad['name'].'" href="'.$go_url.'" target="_blank">';
                $html .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '.$size_html.' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
                $html .= '<param name="movie" value="'.__ROOT__.'data/upload/advert/'.$ad['content'].'" />';
                $html .= '<param name="quality" value="autohigh" />';
                $html .= '<param name="wmode" value="opaque" />';
                $html .= '<embed src="'.__ROOT__.'/data/upload/advert/'.$ad['content'].'" quality="autohigh" wmode="opaque" name="flashad" swliveconnect="TRUE" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" '.$size_html.'></embed>';
                $html .= '</object>';
                $html .= '</a>';
                break;
            case 'indexbg':
                $html  = '<style type="text/css">';
                $html .= ".bg-ad {width: 100%;height: {$board_info['height']}px;position: fixed;top: 0;}";
                $html .= ' .bg-ad a{display: block;height: 100%;background-position: top center;background-repeat: no-repeat;}';
                $html .= ' .container{position:relative;z-index: 1;margin-top: 98px;padding-top: 15px; border-radius: 5px 5px 0 0;}';
                $html .= ' .top-bar{border-top: 1px solid #c6c6c6;}';
                $html .= ' </style>';

                $html .= ' <div style="display: block;overflow: hidden;">';
                $html .= '     <div class="bg-ad">';
                $html .= '         <a target="_blank" href="'.$go_url.'" title="'.$ad['name'].'" style="background-image:url('.get_img($ad['content']).')"></a>';
                $html .= '     </div>';
                $html .= '  </div>';
                break;
        }
        return $html;
    }
}